/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
 * Description: Hmfs-tools resize load
 */

#ifndef RESIZE_LOAD_H
#define RESIZE_LOAD_H

#include <iostream>

#include "hmfs_fs.h"
#include "hmfs_log.h"
#include "resize_data.h"
#include "resize_utils.h"

namespace OHOS {
namespace Hmfs {
class LoadSit;
class ResizeLoad {
public:
    ResizeLoad(std::shared_ptr<HmfsConfigData> &configData, std::shared_ptr<HmfsSuperBlockInfo> &superBlockInfo);
    ~ResizeLoad() = default;
    void InitSuperBlockInfo();
    int32_t HmfsShouldProceed(SuperBlockData *superBlockData, uint32_t flag);
    int32_t UpdateSbFeatures();
    void *GetBitmapPtr(uint32_t flag);
    uint32_t GetStartCpAddr();
    uint32_t GetNextFreeBlockAddr(CurrentSegmentInfo *currentSegment);
    bool HmfsIsValidBlockAddr(uint32_t blkaddr, int32_t type);
    FsyncInodeEntry *GetFsyncInode(struct ListNode *head, uint32_t inodeNumber);
    FsyncInodeEntry *AddFsyncinode(struct ListNode *head, uint32_t inodeNumber);
    int32_t FindFsyncInode(struct ListNode *head);
    int32_t HmfsRaMetaPages(uint32_t start, int32_t numPages, int32_t type);
    int32_t DoRecordFsyncData(NodeData *nodeBlock, uint32_t blkaddr);
    int32_t RecordFsyncData(LoadSit &loadSit);
    int32_t HmfsLoadData();
    std::shared_ptr<HmfsConfigData> GetConfig();
    std::shared_ptr<HmfsSuperBlockInfo> GetSuperBlockInfo();

private:
    void InitializeSuperBlockParameters();
    void InitializeDevicePaths();
    void InitializeDeviceSegments();
    void InitializeZonedModel();
    void InitializeSingleDevice();
    void LogSuperBlockInfo();
    int32_t ProcessDataBlocks(NodeData *nodeBlock, uint32_t blockAddr);
    void DelFsyncInode(FsyncInodeEntry *entry);
    int32_t TraverseDnodes(struct ListNode *inodeList);
    void DestroyFsyncDnodes(struct ListNode *head);
    int32_t ProcessNodeBlock(struct ListNode *head, NodeData *nodeBlock, uint32_t blockAddr,
        uint32_t &loopCount, uint32_t freeBlocks);
    std::shared_ptr<HmfsConfigData> config_ = nullptr;
    std::shared_ptr<HmfsSuperBlockInfo> superBlockInfo_ = nullptr;
};
} // namespace Hmfs
} // namespace OHOS
#endif // RESIZE_LOAD_H
